﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Collections.Generic;

namespace Takkou.Language
{
    public abstract class Var
    {
        // STATIC members
        // Var table definition and access
        protected static List<Var> VAR_TABLE = new List<Var>();
        public static Var Get(string name)
        {
            foreach (Var v in VAR_TABLE)
            {
                if (v.Name == name)
                    return v;
            }
            return null;
        }

        public enum VarType
        {
            NUMBER,
            STRING
        }

        // common properties
        public string Name { get; private set; }
        public abstract VarType Type { get; }

        public Var(List<Var> table, string name )
        {
            Name = name;
            table.Add(this);  // each created variable is added in the var definition table
        }
    }

    // concrete variable of type "number"
    public class NumberVar : Var, Number
    {
        public Number Value { get; set; }
        public override VarType Type {
            get {
                return VarType.NUMBER;
            }
        }

        public NumberVar(string name, Number value) 
            : base(VAR_TABLE, name)
        {
            Value = value;
        }

        public NumberVar(Block block, string name, Number value)
            : base(block.table, name)
        {
            Value = value;
        }

        // override Number get() method
        public double get()
        {
            return Value.get();
        }
    }

    // concrete variable of type "string"
    public class StringVar : Var, String
    {
        public String Value { get; set; }
        public override VarType Type
        {
            get
            {
                return VarType.STRING;
            }
        }

        public StringVar(string name, String value) 
            : base(VAR_TABLE, name)
        {
            Value = value;
        }

        public StringVar(Block block, string name, String value)
            : base(block.table, name)
        {
            Value = value;
        }

        // override String get() method
        public string get()
        {
            return Value.get();
        }
    }
}
